%Scatter plots with R^2 values for the
function fig_CIP_alphaVSWelfareScatter(Alphas,Welfare,currSelector,optfig)

%For graphs of extremes of price impact
truncationpoint = -Inf;
truncationselector = Welfare(:,currSelector)>truncationpoint;
R2s = [0 0];
R2s(1,1) = corr(Welfare(:,currSelector),Alphas(:,currSelector))^2;
R2s(1,2) = corr(Welfare(truncationselector,currSelector),Alphas(truncationselector,currSelector))^2;
CurrencyNames = {' AUD/USD',' GBP/USD',' CAD/USD',' EUR/USD',' JPY/USD'};
CurrencyNamesFileNames = {'AUDUSD','GBPUSD','CADUSD','EURUSD','JPYUSD'};

functionFolder = cd('.');

if optfig.plotfig ==1
    
    [fontname,dimension,lw,folder,color,style,marker,markersize,fontsize_tit,fontsize_ax,fontsize_lab,fontsize_leg] = fn_optfig(optfig);
    
    fig = figure('Units','inches','Position',dimension);
    
    scatter(Alphas(:,currSelector),Welfare(:,currSelector))
    xlabel('Alpha Coefficient (Price Impact)','interpreter','latex','FontSize',fontsize_lab,'FontName',fontname)
    ylabel('Welfare Gains ($M)','interpreter','latex','FontSize',fontsize_lab,'FontName',fontname)
    title(strcat(CurrencyNames{1,currSelector}), 'interpreter','latex','FontSize',fontsize_tit,'FontName',fontname)
    grid; box off;
    annotation(fig,'textbox',...
        [0.668056019070322 0.186195826645265 0.127724672228844 0.0449438202247191],...
        'String',{strcat('$$R^2$$','=',num2str(round(R2s(1,2),3)))},...
        'FitBoxToText','off','interpreter','latex','FontSize',fontsize_leg,'FontName',fontname,'LineStyle','none');
end

%Now select out only extreme events

oldFolder = cd('output\'); %#ok<NASGU>
save(strcat('Correlations_ScatterAlphasWelfare',CurrencyNamesFileNames{1,currSelector}),'R2s');
saveas(gcf,'xx_ScatterAlphavsWelfares','epsc')
saveas(gcf,strcat('xx_ScatterAlphavsWelfares',CurrencyNamesFileNames{1,currSelector}),'epsc')
cd(functionFolder);


end